import request from '/src/axios.js';
import {baseUrl} from '/src/config/env.js';
import website from "/src/config/website.js";

export const authApi = {
  loginByUsername: (tenantId, account, password, type, key, code) => request({
    url: baseUrl + '/api-uaa/oauth/token',
    method: 'post',
    params: {
      grant_type: (website.captchaMode ? "password_code" : "password"),
      tenantId: tenantId,
      username: account,
      password: password,
      deviceId: key,
      validCode: code,
    }
  }),
  loginBySocial: (tenantId, source, code, state) => request({
    url: '/api/blade-auth/token',
    method: 'post',
    headers: {
      'Tenant-Id': tenantId
    },
    params: {
      tenantId,
      source,
      code,
      state,
      grantType: "social",
      scope: "all",
    }
  }),
  getUserInfo: () => request({
    url: baseUrl + '/user/getUserInfo',
    method: 'get'
  }),
  getCurrentUserInfo: () => request({
    url: baseUrl + '/api-user/users/current',
    method: 'get'
  }),
  refreshToken: (refreshToken, tenantId) => request({
    // url: baseUrl + '/api-uaa/oauth/token?grant_type=refresh_token&refresh_token='+refrshToken,
    url: baseUrl + '/api-uaa/oauth/token',
    method: 'post',
    params: {
      grant_type: "refresh_token",
      refresh_token: refreshToken,
      tenantId: tenantId
    }
  }),
  renewToken: (refreshToken, tenantId) => request({
    // url: baseUrl + '/api-uaa/oauth/token?grant_type=refresh_token&refresh_token='+refrshToken,
    url: baseUrl + '/api-uaa/tokens/renew',
    method: 'get',
  }),
  registerGuest: (form, oauthId) => request({
    url: '/api/blade-user/register-guest',
    method: 'post',
    params: {
      tenantId: form.tenantId,
      name: form.name,
      account: form.account,
      password: form.password,
      oauthId
    }
  }),

  getAuthMenu: () => request({
    url: baseUrl + '/api-user/menus/auth',
    method: 'get'
  }),
  getTopMenu: (topId) => request({
    // url: baseUrl + '/api-user/menus/findAlls',
    // url: baseUrl + '/api-user/topmenu/getMenuByTopId',
    url: baseUrl + '/api-user/topmenu/list',
    method: 'get',
    params: {
      topId
    }
  }),
  getTopMenuById: (topId) => request({
    // url: baseUrl + '/api-user/menus/findAlls',
    // url: baseUrl + '/api-user/topmenu/getMenuByTopId',
    url: baseUrl + '/api-user/topmenu/getTopMenuById',
    method: 'get',
    params: {
      id: topId
    }
  }),
  getCaptcha: () => request({
    // url: '/api/blade-auth/captcha',
    url: baseUrl + '/api-uaa/validata/code',
    method: 'get'
  }),
  sendLogs: (list) => request({
    url: baseUrl + '/user/logout',
    method: 'post',
    data: list
  }),
  logout: () => request({
    url: baseUrl + '/api-uaa/oauth/remove/token',
    method: 'get'
  })

}
